package swing_framework;

import java.awt.BorderLayout;
import java.awt.Color;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import data_transfer.DataCollections;

public class DataPanel {
	private JPanel rightJPanel;
	private static JTable dataListTable;
	private static Object[] tableHeader = { "m", "ts" };

	public JPanel createDataPanel() {
		rightJPanel = new JPanel();
		rightJPanel.setLayout(new BorderLayout());
		rightJPanel.add(createScrollPanel(), BorderLayout.CENTER);
		return rightJPanel;
	}

	private JScrollPane createScrollPanel() {
		JScrollPane dataSrollPanel = new JScrollPane(createDataTable());
		dataSrollPanel.setBackground(Color.BLUE);
		return dataSrollPanel;
	}

	private JTable createDataTable() {
		dataListTable = new JTable();
		return dataListTable;
	}

	@SuppressWarnings("unchecked")
	public static void updateTable() {
		DefaultTableModel dtm = new DefaultTableModel(tableHeader, 0);
		for (int i = 0; i < DataCollections.dataEntities.size(); i++) {
			@SuppressWarnings("rawtypes")
			Vector v = new Vector();
			v.add(DataCollections.dataEntities.get(i).getM());
			v.add(DataCollections.dataEntities.get(i).getTs());
			dtm.addRow(v);
		}
		dataListTable.setModel(dtm);	
		dataListTable.setRowHeight(30);
        dataListTable.repaint();
		dataListTable.updateUI();
	}
}
